import UI.FriendListUI;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Test1 extends JFrame {

    public Test1() {
        // 初始化界面
        initializeUI();
    }

    private void initializeUI() {
        // 设置窗口大小
        setSize(400, 400);

        // 假设friendList是一个字符串列表
        String[] friendList1 = {"Alice", "Bob", "Charlie", "David"};

        int size = friendList1.length;
        int padding = 10;
        int buttonWidth = 80;
        int buttonHeight = 30;
        int cols = 5; // 每行显示5个按钮

        for (int i = 0; i < size; i++) {
            String name = friendList1[i];
            System.out.println("读取到好友:" + name);
            JButton button = new JButton(name);
            button.setBounds(padding + (buttonWidth + padding) * (i % cols),
                    padding + (buttonHeight + padding) * (i / cols),
                    buttonWidth, buttonHeight);
            this.getContentPane().add(button);
        }

        // 重新验证布局
        this.getContentPane().validate();
    }

    public static void main(String[] args) {
        Test1 frame = new Test1();

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}
